package com.yaoli.ajob;

/**
 * Created by will on 2017/4/23.
 *
 * 使用数组 记录 两个数的差
 *
 *
 */
public class _413_ArithmeticSlices {
    public static void main(String[] args) {
        _413_ArithmeticSlices arithmeticSlices = new _413_ArithmeticSlices();
        int nums [] = {1,3,5,7,8,9};

        System.out.println(arithmeticSlices.numberOfArithmeticSlices(nums));
    }
    public int numberOfArithmeticSlices(int[] A) {
        if(A.length <= 2){
            return 0;
        }

        int dp [] = new int[A.length - 1];

        for(int i = 0 ; i < dp.length ; i ++){
            dp [i] = A[i + 1] - A[i];
        }


        int res = 0;

        int count = 1;

        for(int i = 0 ; i < dp.length - 1; i++){
            if(dp[i] == dp[i + 1]){
                count ++;
            }else{
                if(count == 2){
                    res ++;
                }else{
                    res = res + (count )*(count-1)/2 ;
                }

                count = 1;
            }
        }

        if(count == 2){
            res ++;
        }else{
            res = res + (count )*(count-1)/2 ;
        }

        return res;


    }
}
